package com.meshnetics.gb.stack.core.event.system;

import com.meshnetics.gb.Context;

/**
 * SystemStackEvent indication some failure.
 * In addition to SystemStackEvent it may contain an Throwable as a source of this event.
 *
 * @author mmarkov
 */
public class FailureStackEvent extends SystemStackEvent {
    /** Source Throwable of the failure (may be null). */
    protected Throwable t;

    /**
     * Constructs FailureStackEvent having the given name, code and no Context.
     *
     * @param name the name of FailureStackEvent
     * @param code system code of FailureStackEvent
     */
    public FailureStackEvent(String name, int code) {
        this(name, code, null, null);
    }

    /**
     * Constructs FailureStackEvent having the given name, code and context.
     *
     * @param name the name of FailureStackEvent
     * @param code system code of FailureStackEvent
     * @param ctx the Context of FailureStackEvent (could be null)
     */
    public FailureStackEvent(String name, int code, Context ctx) {
        this(name, code, null, ctx);
    }

    /**
     * Constructs FailureStackEvent having the given name, code, t and no Context.
     *
     * @param name the name of FailureStackEvent
     * @param code system code of FailureStackEvent
     * @param t source Throwable of this event (could be null)
     */
    public FailureStackEvent(String name, int code, Throwable t) {
        this(name, code, t, null);
    }

    /**
     * Constructs FailureStackEvent having the given name, code, t and context.
     *
     * @param name the name of FailureStackEvent
     * @param code system code of FailureStackEvent
     * @param t source Throwable of this event (could be null)
     * @param ctx the Context of FailureStackEvent (could be null)
     */
    public FailureStackEvent(String name, int code, Throwable t, Context ctx) {
        super(name, code, ctx);
        this.t = t;
    }

    /**
     * Returns source Throwable of this event or null if none was set.
     *
     * @return source Throwable of this event or null if none was set
     */
    public Throwable getThrowable() {
        return t;
    }

    /**
     * Sets source Throwable of thie event to the given value.
     *
     * @param t new source Throwable value
     */
    public void setThrowable(Throwable t) {
        this.t = t;
    }
}
